package mamma.dao;

import java.util.Date;
import java.util.List;

import mamma.common.MybatisConfig;
import mamma.vo.CalendarVo;
import mamma.vo.InformationVo;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class CalendarDao {
	private SqlSessionFactory factory;
	
	public CalendarDao(){
		factory = MybatisConfig.getSqlSessionFactory();
	}
	
	
	public List<InformationVo> clist(){		//공지일정 리스트가져오기
		SqlSession ss=null;
		List<InformationVo> infoList=null;
		try {
			ss=factory.openSession();
			infoList=ss.selectList("calendar.selectinfo");
			ss.commit();
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		} finally{
			if(ss!=null) ss.close();
		} return infoList;
	}
	
	public List<InformationVo> clist2(){	//고객일정리스트 가져오기
		SqlSession ss=null;
		List<InformationVo> infoList2=null;
		try {
			ss=factory.openSession();
			infoList2=ss.selectList("calendar.selectinfo2");
			ss.commit();
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		} finally{
			if(ss!=null) ss.close();
		} return infoList2;
	}
	
	public void scheduleIns(CalendarVo vo){	//스케줄 추가
		SqlSession ss=null;
		try {
			ss=factory.openSession();
			ss.insert("calendar.insertSchedule",vo);
			ss.commit();
		} catch (Exception e) {
			// TODO: handle exception
		} finally{
			if(ss!=null) ss.close();
		}
	}
	
	public void scheduleDelC(int id){		//고객글삭제
		SqlSession ss=null;
		try {
			ss=factory.openSession();
			ss.delete("calendar.deleteScheduleC",id);
			ss.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
	}
	public void scheduleShiftC(CalendarVo vo){ //고객글이동
		SqlSession ss=null;
		try {
			ss=factory.openSession();
			ss.update("calendar.shiftSchedule", vo);
			ss.commit();
		} catch (Exception e) {
			// TODO: handle exception
		} finally{
			if(ss!=null) ss.close();
		}
		
	}
	
	public void scheduleUpd(CalendarVo vo){	//고객글 수정
		SqlSession ss=null;
		try {
			ss=factory.openSession();
			ss.update("calendar.updateSchedule", vo);
			ss.commit();
		} catch (Exception e) {
			// TODO: handle exception
		} finally{
			if(ss!=null) ss.close();
		}
	}
	
	public void scheduleScr(CalendarVo vo){	//고객글 일정이동
		SqlSession ss=null;
		try {
			ss=factory.openSession();
			ss.update("calendar.scrSchedule", vo);
			ss.commit();
		} catch (Exception e) {
			// TODO: handle exception
		} finally{
			if(ss!=null) ss.close();
		}
	}
	
	public List<InformationVo> selectNews(){
		SqlSession session = factory.openSession();
		List<InformationVo> list = session.selectList("calendar.selectNews");
		return list;
	}
	
}
